﻿using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Web.IBLL;
using Web.Model;

namespace Web.BLL
{
    public class HouseBLL:IHouseBLL
    {
        public HouseBLL(IBaseDAL<HouseClass> dAL,IBaseDAL<HouseType> dAL1)
        {
            DAL = dAL;
            DAL1 = dAL1;
        }

        public IBaseDAL<HouseClass> DAL { get; }
        public IBaseDAL<HouseType> DAL1 { get; }

        public Task<int> HAdd(HouseClass h)
        {
            return DAL.AddAsync(h);
        }

        public dynamic HShow(int Pageindex, int Pagesize, int HNum)
        {
            var data = DAL.GetAll();
            var leve = DAL1.GetAll();
            var list = from a in data
                       join b in leve
                       on a.HTId equals b.HTId
                       select new
                       {
                           a.HId,
                           a.HName,
                           a.HNum,
                           a.Img,
                           a.IsDelete,
                           b.HTId,
                           b.HTName
                       };
            if (HNum > 0)
            {
                list = list.Where(x => x.HNum == HNum);
            }
            var c = list.Count();
            var d = list.OrderBy(x => x.HId).Skip((Pageindex - 1) * Pagesize).Take(Pagesize).ToList();
            return new
            {
                count = c,
                list =d
            };
        }

        public Task<int> TAdd(HouseType t)
        {
            return DAL1.AddAsync(t);
        }

        public List<HouseType> Xia()
        {
            return DAL1.GetAll().ToList();
        }
    }
}
